<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OpenShoe: sleepmgr.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenShoe
   &#160;<span id="projectnumber">0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">sleepmgr.h</div>  </div>
</div>
<div class="contents">
<a href="sleepmgr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef SLEEPMGR_H</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define SLEEPMGR_H</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;<a class="code" href="compiler_8h.html" title="Compiler file for AVR32.">compiler.h</a>&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;<a class="code" href="sleep_8h.html" title="Sleep mode access.">sleep.h</a>&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;<a class="code" href="parts_8h.html" title="Arch file for AVR32.">parts.h</a>&gt;</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="preprocessor">#if defined(XMEGA)</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor"># include &quot;xmega/sleepmgr.h&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#elif (defined(__GNUC__) &amp;&amp; defined(__AVR32__)) || (defined(__ICCAVR32__) || defined(__AAVR32__))</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor"># include &quot;<a class="code" href="uc3_2sleepmgr_8h.html" title="AVR UC3 Sleep manager implementation.">uc3/sleepmgr.h</a>&quot;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#else</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor"># error Unsupported device.</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span>
<a name="l00086"></a>00086 <span class="preprocessor">#if defined(__DOXYGEN__) &amp;&amp; !defined(CONFIG_SLEEPMGR_ENABLE)</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#  define CONFIG_SLEEPMGR_ENABLE</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>
<a name="l00104"></a>00104 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> sleepmgr_init(<span class="keywordtype">void</span>)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 <span class="preprocessor">#ifdef CONFIG_SLEEPMGR_ENABLE</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span>        uint8_t i;
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a02fd0aaf6162fa103be2aa0b2593a984">SLEEPMGR_NR_OF_MODES</a> - 1; i++) {
<a name="l00110"></a>00110                 sleepmgr_locks[i] = 0;
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112         sleepmgr_locks[SLEEPMGR_NR_OF_MODES - 1] = 1;
<a name="l00113"></a>00113 <span class="preprocessor">#endif </span><span class="comment">/* CONFIG_SLEEPMGR_ENABLE */</span>
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00124"></a>00124 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> sleepmgr_lock_mode(<span class="keyword">enum</span> <a class="code" href="group__sleepmgr__group.html#gaa990bc3ea16fcad09009cdc70dbc38c6" title="Sleep mode locks.">sleepmgr_mode</a> mode)
<a name="l00125"></a>00125 {
<a name="l00126"></a>00126 <span class="preprocessor">#ifdef CONFIG_SLEEPMGR_ENABLE</span>
<a name="l00127"></a>00127 <span class="preprocessor"></span>        <a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags;
<a name="l00128"></a>00128 
<a name="l00129"></a>00129         Assert(sleepmgr_locks[mode] &lt; 0xff);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131         <span class="comment">// Enter a critical section</span>
<a name="l00132"></a>00132         flags = cpu_irq_save();
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         ++sleepmgr_locks[mode];
<a name="l00135"></a>00135 
<a name="l00136"></a>00136         <span class="comment">// Leave the critical section</span>
<a name="l00137"></a>00137         cpu_irq_restore(flags);
<a name="l00138"></a>00138 <span class="preprocessor">#endif </span><span class="comment">/* CONFIG_SLEEPMGR_ENABLE */</span>
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00149"></a>00149 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> sleepmgr_unlock_mode(<span class="keyword">enum</span> <a class="code" href="group__sleepmgr__group.html#gaa990bc3ea16fcad09009cdc70dbc38c6" title="Sleep mode locks.">sleepmgr_mode</a> mode)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151 <span class="preprocessor">#ifdef CONFIG_SLEEPMGR_ENABLE</span>
<a name="l00152"></a>00152 <span class="preprocessor"></span>        <a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags;
<a name="l00153"></a>00153 
<a name="l00154"></a>00154         Assert(sleepmgr_locks[mode]);
<a name="l00155"></a>00155 
<a name="l00156"></a>00156         <span class="comment">// Enter a critical section</span>
<a name="l00157"></a>00157         flags = cpu_irq_save();
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         --sleepmgr_locks[mode];
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         <span class="comment">// Leave the critical section</span>
<a name="l00162"></a>00162         cpu_irq_restore(flags);
<a name="l00163"></a>00163 <span class="preprocessor">#endif </span><span class="comment">/* CONFIG_SLEEPMGR_ENABLE */</span>
<a name="l00164"></a>00164 }
<a name="l00165"></a>00165 
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 <span class="preprocessor">#endif </span><span class="comment">/* SLEEPMGR_H */</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Mon Dec 19 2011 21:04:51 for OpenShoe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
